package controller;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class CartForm extends HttpServlet
{
	HttpSession session;
	public void doGet(HttpServletRequest request, HttpServletResponse response)
	{
		session = request.getSession(true);		
		
		try 
		{
			String address = "";
			if (IsCustomerLoggedIn()) 
			{
				address = "/WEB-INF/checkout.jsp";
				RequestDispatcher dispatcher = request.getRequestDispatcher(address);
				dispatcher.forward(request, response);					
			}
			else
			{
				address = "../login.jsp";
				response.sendRedirect(address);			
			}		
		} catch (ServletException e) { e.printStackTrace();
		} catch (IOException e) { e.printStackTrace();
		}			
	}
	
	private boolean IsCustomerLoggedIn() 
	{
		boolean isLoggedIn = false;		
		if(session.getAttribute("customer")!= null) { isLoggedIn = true; }
		return isLoggedIn;
	}
}
